from typing import List


class Solution:
    def sortedSquares(self, nums: List[int]) -> List[int]:
        l = len(nums)
        result = [0] * l
        left, right, cur = 0, l - 1, l - 1
        while cur >= 0:
            if nums[left] ** 2 > nums[right] ** 2:
                result[cur] = nums[left] ** 2
                left += 1
            else:
                result[cur] = nums[right] ** 2
                right -= 1
            cur -= 1
        return result
